﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SignalR.Hubs;

namespace SignalRTest
{
     [HubName("chatHub")]
    public class ChatHub : Hub
    {
        private readonly int TimeoutInSeconds = 30;
        private readonly Chat _chat;

        public ChatHub() : this(Chat.Instance) { }

        public ChatHub(Chat chat)
        {
            _chat = chat;
        }

        public void Join(string myName)
        {
            if (Chat.Clients.Where(x => x.Name.Equals(myName)).Count().Equals(0))
            {
                Chat.Clients.Add(new Client() { Name = myName, LastResponse = DateTime.Now });
                SendMessageServer(string.Format("{0} entered the chat", myName));
                GetClients();
                Caller.Naam = myName;
            }
            else
                throw new Exception("This login is allready in use");
        }
    }
}
